import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

//路由跳转前
router.beforeEach((to, from, next) => {
  let user = store.getters.getUser;

  let isLogin = user.username && user.username != "";
  console.log(isLogin);

  //诸如此类，写得太不好了，还是看正式项目比较好
  if (isLogin) {
    if (to.path == '/login') {
      next({ path: '/main' });
    } else if (to.path == '/logout') {
      store.dispatch('asyncLogout');
      next({ path: '/login' });
    } else {
      next();
    }
  } else {
    if (to.path != "/login") {
      next({ path: '/login' });
    }
  }

  next();
});


Vue.use(ElementUI)

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
